﻿using System;
using System.Net;
using System.Xml;
using System.Linq;
using System.Xml.Linq;

namespace RFW.Weather
{
	public class CurrentConditions
	{
		private WeatherFlash.WeatherFlash _weatherFlash = null;

		public event System.EventHandler DownloadComplete;
		public event System.EventHandler DownloadFailed;

		public DateTime TimeStamp { get; internal set; }
		public DateTime TimeOfUpdate { get; internal set; }
		public WeatherFlash.Wind Wind { get; internal set; }
		public WeatherFlash.Humidity InHumidity { get; internal set; }
		public WeatherFlash.Humidity Humidity { get; internal set; }
		public WeatherFlash.Temperature InTemperature { get; internal set; }
		public WeatherFlash.Temperature Temperature { get; internal set; }
		public WeatherFlash.Barometer Barometer { get; internal set; }
		public WeatherFlash.Rain Rain { get; internal set; }
		public WeatherFlash.Solar Solar { get; internal set; }
		public WeatherFlash.Forecast Forecast { get; internal set; }

		public decimal PressureAltitude { get; internal set; }
		public decimal CloudBase { get; internal set; }
		public decimal DensityAltitude { get; internal set; }
		public decimal VirtualTemperature { get; internal set; }
		public decimal VaporPressure { get; internal set; }

		public CurrentConditions()
			: this(string.Empty)
		{
		}

		public CurrentConditions(string weatherFlashURI)
		{
			if (weatherFlashURI.Trim().Length == 0)
				_weatherFlash = new WeatherFlash.WeatherFlash(this);
			else
				_weatherFlash = new WeatherFlash.WeatherFlash(this, weatherFlashURI);

			_weatherFlash.DownloadComplete += _weatherFlash_DownloadComplete;
			_weatherFlash.DownloadFailed += _weatherFlash_DownloadFailed;
		}

		void _weatherFlash_DownloadFailed(object sender, EventArgs e)
		{
			if (DownloadFailed != null)
				DownloadFailed(this, e);
		}

		void _weatherFlash_DownloadComplete(object sender, EventArgs e)
		{
			if (DownloadComplete != null)
				DownloadComplete(this, e);
		}

		public void Get()
		{
			_weatherFlash.Get();
		}
	}
}
